
const mysql = require('mysql2/promise');



module.exports = async (app) => {

    // 创建连接池，设置连接池的参数
    const pool = mysql.createPool({
        host: 'localhost',
        user: app.config.db.user,
        password: app.config.db.password,
        database: app.config.db.database,
        waitForConnections: true,
        connectionLimit: 10,
        maxIdle: 10, // 最大空闲连接数，默认等于 `connectionLimit`
        idleTimeout: 60000, // 空闲连接超时，以毫秒为单位，默认值为 60000 ms
        queueLimit: 0,
        enableKeepAlive: true,
        keepAliveInitialDelay: 0,
    });

    try {
        await pool.getConnection();
        app.pool = pool;
    } catch (error) {
        app.logger.error('[-- exception --]:', error);
    }
}